#include "capturefileviewer.h"
#include <QFileDialog>
#include <QStringList>
#include <QHeaderView>
#include <QTableWidgetItem>
#include <QList>
#include <QFileInfo>
#include <iostream>
#include <qmath.h>
#include <QDir>
#include <QDebug>
#include <QMessageBox>

CaptureFileViewer::CaptureFileViewer(QWidget *parent)
    : QWidget(parent)
{
    initScene();
    initWindow();
}

CaptureFileViewer::~CaptureFileViewer()
{

}

void CaptureFileViewer::initScene()
{
    captureScene = new QGraphicsScene;
    captureView = new QGraphicsView;
    captureView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    captureView->setDragMode(QGraphicsView::RubberBandDrag);
    captureView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
    captureView->setScene(captureScene);
    captureView->resize(800,600);
}

void CaptureFileViewer::initWindow()
{
    sliderZoom = new QSlider(Qt::Vertical);
    sliderZoom->setMinimum(0);
    sliderZoom->setMaximum(500);
    sliderZoom->setValue(250);
    sliderZoom->setTickPosition(QSlider::TicksRight);
    sliderCams = new QSlider(Qt::Horizontal);
    sliderCams->setTickPosition(QSlider::TicksBelow);
    sliderCams->setMinimum(0);
    sliderCams->setMaximum(PFCMU::CAMS-1);
    sliderFrames = new QSlider(Qt::Horizontal);
    sliderFrames->setTickPosition(QSlider::TicksBelow);
    labelCams = new QLabel(tr("CAMS"));
    labelCurrentCam = new QLabel(tr("%1").arg(sliderCams->value()));
    labelFrames = new QLabel(tr("FRAMES"));
    labelMinTimeStamp = new QLabel(tr("Min"));
    labelMaxTimeStamp = new QLabel(tr("Max"));
//    labelCurrentTimeStamp = new QLabel(tr("Current"));
    txtCurrentFrame = new QLineEdit(tr("Current Frame"));
    txtCurrentFrame->setFixedWidth(120);
    btnGoFrame = new QPushButton(tr("Go"));
    btnGoFrame->setFixedWidth(30);

    gbxFps = new QGroupBox(tr("Select Fps"));
    gbxFps->setFixedWidth(200);
    fpsHLayout = new QHBoxLayout();
    rdo25Fps = new QRadioButton(tr("25fps"));
    rdo100Fps = new QRadioButton(tr("100fps"));
    rdo25Fps->setChecked(true);
    fpsHLayout->addWidget(rdo25Fps);
    fpsHLayout->addWidget(rdo100Fps);
    fpsHLayout->addStretch(1);
    gbxFps->setLayout(fpsHLayout);
    setTimeStampInc();

    txtBatchFileName = new QLineEdit();
    txtBatchFileName->setFixedWidth(200);
    buttonLoadBatchFiles = new QPushButton("Load rcaptured");

    buttonAddFile = new QPushButton(tr("Add File"));
    buttonRemoveFile = new QPushButton(tr("Remove File"));
    buttonRefresh = new QPushButton(tr("Refresh View"));
    buttonSaveImg=new QPushButton(tr("Save Image"));
//    txtImgBaseName=new QLineEdit();
//    txtImgBaseName->setText("img");
//    txtImgBaseName->setFixedWidth(90);
    labelSaveFrames = new QLabel(tr("Save Frames:"));
    labelSaveFrames->setFixedWidth(90);
    txtImgSaveCount=new QLineEdit();
    txtImgSaveCount->setText("1");
    txtImgSaveCount->setFixedWidth(50);
    buttonAutoSaveImg=new QPushButton(tr("Auto Save"));

    fileList = new QTableWidget();
    fileList->setFixedWidth(200);
    fileList->setColumnCount(1);
    fileList->setHorizontalHeaderLabels(QStringList(tr("File Name")));
    fileList->horizontalHeader()->resizeSection(0,200);

    camsSpliterHLayout = new QHBoxLayout();
    camsSpliterHLayout->addWidget(labelCams);
    camsSpliterHLayout->addWidget(labelCurrentCam);
    camsSpliterHLayout->addWidget(sliderCams);

    framesSpliterHLayout = new QHBoxLayout();
    framesSpliterHLayout->addWidget(labelFrames);
//    framesSpliterHLayout->addWidget(labelCurrentTimeStamp);
    framesSpliterHLayout->addWidget(txtCurrentFrame);
    framesSpliterHLayout->addWidget(btnGoFrame);
    framesSpliterHLayout->addWidget(labelMinTimeStamp);
    framesSpliterHLayout->addWidget(sliderFrames);
    framesSpliterHLayout->addWidget(labelMaxTimeStamp);

    buttonViewAll = new QPushButton(tr("All Files"));
    buttonViewAll->setCheckable(true);
    buttonViewAll->setChecked(true);
    buttonViewAll->setEnabled(false);
    buttonViewAll->setMaximumWidth(100);
    labelSingleView = new QLabel(tr("Not set"));
    buttonPlay = new QPushButton(tr(">"));
    buttonPlay->setFixedWidth(25);
    buttonPlay->setLayoutDirection(Qt::RightToLeft);
    buttonPlay->setEnabled(false);
    buttonPause = new QPushButton(tr("||"));
    buttonPause->setFixedWidth(25);
    buttonPause->setLayoutDirection(Qt::RightToLeft);
    buttonPause->setEnabled(false);
    playHLayout = new QHBoxLayout();
    playHLayout->addWidget(buttonViewAll);
    playHLayout->addWidget(labelSingleView);
    playHLayout->addWidget(buttonPlay);
    playHLayout->addWidget(buttonPause);
    playHLayout->addSpacing(50);


    viewHLayout = new QHBoxLayout();
    viewHLayout->addWidget(captureView);
    viewHLayout->addWidget(sliderZoom);

    viewVLayout = new QVBoxLayout();
    viewVLayout->addLayout(playHLayout);
    viewVLayout->addLayout(viewHLayout);
    viewVLayout->addLayout(camsSpliterHLayout);
    viewVLayout->addLayout(framesSpliterHLayout);

    listVLayout = new QVBoxLayout();
    listVLayout->addWidget(fileList);
    listVLayout->addWidget(gbxFps);
    batchLoadHLayout = new QHBoxLayout();
    //batchLoadHLayout->addWidget(txtBatchFileName);
    //batchLoadHLayout->addWidget(buttonLoadBatchFiles);
    listVLayout->addWidget(txtBatchFileName);
    listVLayout->addWidget(buttonLoadBatchFiles);
    //listVLayout->addLayout(batchLoadHLayout);
    listVLayout->addWidget(buttonAddFile);
    listVLayout->addWidget(buttonRemoveFile);
    listVLayout->addWidget(buttonRefresh);
//    listVLayout->addWidget(buttonSaveImg);

    saveImgHLayout=new QHBoxLayout();
//    saveImgHLayout->addWidget(txtImgBaseName);
    saveImgHLayout->addWidget(labelSaveFrames);
    saveImgHLayout->addWidget(txtImgSaveCount);
    listVLayout->addLayout(saveImgHLayout);

    chbCreateFolder = new QCheckBox(tr("Create cam folders"));
    listVLayout->addWidget(chbCreateFolder);
    listVLayout->addWidget(buttonAutoSaveImg);

    buttonTest = new QPushButton(tr("Test"));
//    listVLayout->addWidget(buttonTest);
    connect(buttonTest,SIGNAL(clicked()),SLOT(onTestButton()));
    connect(this,SIGNAL(testSignal(int)),SLOT(testSlot(int)));

    mainHLayout = new QHBoxLayout();
    mainHLayout->addLayout(viewVLayout);
    mainHLayout->addLayout(listVLayout);

    this->setLayout(mainHLayout);
    //this->setFixedWidth(720);
    //this->resize(720, 600);

    connect(buttonAddFile, SIGNAL(clicked()), SLOT(onAddFiles()));
    connect(buttonRemoveFile, SIGNAL(clicked()), SLOT(onRemoveFile()));
    connect(buttonRefresh, SIGNAL(clicked()), SLOT(onRefreshView()));
    connect(buttonSaveImg, SIGNAL(clicked()), SLOT(onSaveImg()));
    connect(buttonAutoSaveImg,SIGNAL(clicked()),SLOT(onAutoSaveImg()));
    connect(buttonLoadBatchFiles, SIGNAL(clicked()), SLOT(onLoadBatchFiles()));
    connect(buttonViewAll, SIGNAL(clicked()), SLOT(onSwitchToAll()));
    connect(buttonPlay, SIGNAL(clicked()), SLOT(onPlay()));
    connect(btnGoFrame, SIGNAL(clicked()), SLOT(onGoFrame()));
}

void CaptureFileViewer::onGoFrame()
{
    //
//    QList<QGraphicsItem *> itemsInScene = captureScene->items();
//    for (int i=0; i< itemsInScene.count(); i++) {
//        GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(i));
//        gii->onTimeStampUpdated(txtCurrentFrame->text().toInt());
//    }
    sliderFrames->setValue((txtCurrentFrame->text().toInt()-labelMinTimeStamp->text().toInt())/TIMESTAMPINC);
}

void CaptureFileViewer::onTestButton()
{
//    QFileDialog *fd = new QFileDialog(this);
//    fd->setFileMode(QFileDialog::AnyFile);
//    QString fileName;
//    fd->setDirectory("/home/demo/captured");
//    if(fd->exec()==QDialog::Accepted)
//    {
//        fileName = fd->selectedFiles().at(0);
//    }
//    qDebug(fileName.toAscii());
}

void CaptureFileViewer::testSlot(int value)
{
    std::cout << value << std::endl;
}

void CaptureFileViewer::onAddFiles()
{
    QStringList filesListStr;
    filesListStr = QFileDialog::getOpenFileNames(this, tr("Select Captured Files"), tr("/home"));
    if(filesListStr.count()!=0)
    {
        for(int i=0;i<filesListStr.count();i++)
        {
            QTableWidgetItem *fileRow = new QTableWidgetItem(filesListStr.at(i));
            fileList->insertRow(fileList->rowCount());
            fileList->setItem(fileList->rowCount()-1, 0, fileRow);
        }
    }
}

void CaptureFileViewer::onRemoveFile()
{
    QList<QTableWidgetItem *> selectedFiles = fileList->selectedItems();
    if(selectedFiles.count()!=0)
    {
        for(int i=0;i<selectedFiles.count();i++)
        {
            int rowNumber = selectedFiles.at(i)->row();
            if(rowNumber!=-1)
            {
                fileList->removeRow(rowNumber);
            }
        }
    }
}

void CaptureFileViewer::onRefreshView()
{
    PFCMU::timestamp_t minTimeStamp;
    PFCMU::timestamp_t maxTimeStamp;
    if(fileList->rowCount()>0)
    {
        setTimeStampInc();
        disconnect(sliderFrames, SIGNAL(valueChanged(int)), this, SLOT(onFrameChanged(int)));
        captureScene->clear();
        QString str(fileList->item(0,0)->text());
        QFileInfo fi(str);
        if(fi.exists())
        {
            int width = 640;
            if(TIMESTAMPINC==4)
            {
                width = 640;
            }
            else
            {
                width = 320;
            }
            GraphicsImageItem *gii = new GraphicsImageItem(&str,width);
            minTimeStamp = gii->getMinTimeStamp();
            maxTimeStamp = gii->getMaxTimeStamp();
        }
        else
        {
            for(int i=1;i<fileList->rowCount();i++)
            {
                QString str(fileList->item(i,0)->text());
                QFileInfo fi(str);
                if(fi.exists())
                {
                    int width = 640;
                    if(TIMESTAMPINC==4)
                    {
                        width = 640;
                    }
                    else
                    {
                        width = 320;
                    }
                    GraphicsImageItem *gii = new GraphicsImageItem(&str,width);
                    minTimeStamp = gii->getMinTimeStamp();
                    maxTimeStamp = gii->getMaxTimeStamp();
                    i=fileList->rowCount();
                }
            }
        }
    }

    captureScene->clear();

    for(int i=0;i<fileList->rowCount();i++)
    {
        QString str(fileList->item(i,0)->text());
        QFileInfo fi(str);
        if(fi.exists())
        {
            GraphicsImageItem *gii = new GraphicsImageItem(&str);
            minTimeStamp = std::min(minTimeStamp, gii->getMinTimeStamp());
            maxTimeStamp = std::max(maxTimeStamp, gii->getMaxTimeStamp());
            int xpos = i%4;
            int ypos = i/4;
            gii->setPos(xpos * gii->getWidth(), ypos * gii->getHeight());
            connect(this, SIGNAL(initTimeStamp(PFCMU::timestamp_t)),
                    gii, SLOT(onInitTimeStamp(PFCMU::timestamp_t)));
            connect(this, SIGNAL(timeStampChanged(PFCMU::timestamp_t)),
                    gii, SLOT(onTimeStampUpdated(PFCMU::timestamp_t)));
            connect(this, SIGNAL(camChanged(int)),
                    gii, SLOT(onCamUpdated(int)));
            connect(gii, SIGNAL(switchToSingle(QString*)),
                    this, SLOT(onSwitchToSingle(QString*)));
            captureScene->addItem(gii);
        }
    }
    m_MinFileGroupTimeStamp = minTimeStamp;
    m_MaxFileGroupTimeStamp = maxTimeStamp;
    emit initTimeStamp(minTimeStamp);
    resetFrameSlider(m_MinFileGroupTimeStamp, m_MaxFileGroupTimeStamp);
    sliderZoom->setValue(250);
    connect(sliderZoom, SIGNAL(valueChanged(int)), SLOT(setupViewMatrix(int)));
    connect(sliderFrames, SIGNAL(valueChanged(int)), SLOT(onFrameChanged(int)));
    connect(sliderCams, SIGNAL(valueChanged(int)),SLOT(onCamsChanged(int)));
}

void CaptureFileViewer::onSaveImg()
{
    QList<QGraphicsItem *> itemsInScene = captureScene->items();
    if(itemsInScene.count()>=1)
    {
        QString filePath = QFileDialog::getExistingDirectory(this, "Select a folder", ".");
        if (filePath.isEmpty()) return;
        for (int i=0; i<itemsInScene.count(); i++) {
            GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(i));
//        QFileDialog *fd = new QFileDialog(this);
//        fd->setFileMode(QFileDialog::AnyFile);
//        QString fileName;
//        fd->setDirectory("/home/demo/captured");
//        if(fd->exec()==QDialog::Accepted)
//        {
//            fileName = fd->selectedFiles().at(0);
//        }
            qDebug() << "Widget No " << i << " Filename" << gii->getFileName();
            QString oFilename(gii->getFileName());
            int ind = oFilename.indexOf("ve");
            int panelNo = oFilename.left(ind+4).right(2).toInt();
            QString fPDir;
            fPDir.append(filePath).append("/").append(tr("ve%1").arg(panelNo));
            QDir newDir;
            if (!newDir.exists(fPDir)) {
                newDir.mkdir(fPDir);
            }
            int cc = gii->getCurrentCam();
            QString fCDir;
            fCDir.append(fPDir).append("/").append(tr("cam%1").arg(cc));
            if (!newDir.exists(fCDir)) {
                newDir.mkdir(fCDir);
            }
            QString fileName;
//            fileName.append(fCDir).append("/").append(labelCurrentTimeStamp->text()).append(".bmp");
            qDebug() << fileName;
            gii->saveQImage(fileName);
        }
    }
}

void CaptureFileViewer::onAutoSaveImg()
{
    QList<QGraphicsItem *> itemsInScene = captureScene->items();
//    if(itemsInScene.count()==1)
//    {
//        GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(0));
//        QString fileBaseName="img";
//        QString pathName="/home/demo/captured/imgs/";
//        QString pathName = QFileDialog::getExistingDirectory(this,"Selecte a folder",".");
//        QString fileCount="1";
//        if(txtImgBaseName->text()!="")
//        {
//            fileBaseName=txtImgBaseName->text();
//        }
//        if(txtImgSaveCount->text()!="")
//        {
//            fileCount=txtImgSaveCount->text();
//        }
//        QString fileName(pathName);
//        fileName.append(fileBaseName);
//        fileName.append(fileCount);
//        fileName.append(".bmp");
//        gii->saveQImage(fileName);
//        //qDebug(fileName.toAscii());
//        int count=fileCount.toInt();
//        count++;
//        txtImgSaveCount->setText(QString("%1").arg(count));
//    }
    if(itemsInScene.count()>=1)
    {
        QString filePath = QFileDialog::getExistingDirectory(this, "Select a folder", "/tmpdata");
        if (filePath.isEmpty()) return;
        int count = txtImgSaveCount->text().toInt();
        int orgFrame = sliderFrames->value();
        for (int k=count; k>0; k--) {
            for (int i=0; i<itemsInScene.count(); i++) {
                GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(i));
                QString oFilename(gii->getFileName());
                int ind = oFilename.indexOf("ve");
                int panelNo = oFilename.left(ind+4).right(2).toInt();
                QString fPDir;
                fPDir.append(filePath).append("/").append(tr("ve%1").arg(panelNo));
                if (chbCreateFolder->isChecked()) {
                    QDir newDir;
                    if (!newDir.exists(fPDir)) {
                        newDir.mkdir(fPDir);
                    }
                }
                for (int j=0; j<PFCMU::CAMS; j++) {
                    sliderCams->setValue(j);
                    int cc = gii->getCurrentCam();
                    QString fCDir;
                    if (chbCreateFolder->isChecked()) {
                        fCDir.append(fPDir).append("/").append(tr("cam%1").arg(cc));
                        QDir newDir;
                        if (!newDir.exists(fCDir)) {
                            newDir.mkdir(fCDir);
                        }
                    } else {
                        fCDir.append(fPDir).append("_").append(tr("cam%1").arg(cc));
                    }
                    QString fileName;
                    if (chbCreateFolder->isChecked()) {
                        fileName.append(fCDir).append("/").append(txtCurrentFrame->text()).append(".jpg");
//                        fileName.append(fCDir).append("/").append(labelCurrentTimeStamp->text()).append(".bmp");
                    } else {
                        fileName.append(fCDir).append("_").append(txtCurrentFrame->text()).append(".jpg");
//                        fileName.append(fCDir).append("_").append(labelCurrentTimeStamp->text()).append(".jpg");
                    }
                    qDebug() << fileName;
                    gii->saveQImage(fileName);
                    txtImgSaveCount->setText(tr("%1").arg(count));
                }
            }
            sliderFrames->setValue(sliderFrames->value() + 1);
        }
//        sliderFrames->setValue(orgFrame);
    }
    QMessageBox::information(NULL,tr("Information"), tr("All images saved!"));
}

void CaptureFileViewer::onLoadBatchFiles()
{
    //TODO
    QString fileName = txtBatchFileName->text();
    if(fileName.isEmpty())
    {
        //nothing inputed
    }
    else
    {
        QString filePath("/rcaptured/ve00/");
        filePath.append(txtBatchFileName->text());
        for(int i=1;i<10;i++)
        {
            QString nodeNumber(tr("%1").arg(i));
            filePath.replace(14,1,nodeNumber);
            QTableWidgetItem *fileRow = new QTableWidgetItem(filePath);
            fileList->insertRow(fileList->rowCount());
            fileList->setItem(fileList->rowCount()-1, 0, fileRow);
        }
        for(int i=10;i<=20;i++)
        {
            QString nodeNumber(tr("%1").arg(i));
            filePath.replace(13,2,nodeNumber);
            QTableWidgetItem *fileRow = new QTableWidgetItem(filePath);
            fileList->insertRow(fileList->rowCount());
            fileList->setItem(fileList->rowCount()-1, 0, fileRow);
        }
    }
}

void CaptureFileViewer::setupViewMatrix(int size)
{
    //TODO
    qreal scale = qPow(qreal(2),(size-250)/qreal(50));
    QMatrix matrix;
    matrix.scale(scale,scale);
    matrix.rotate(qreal(0));

    QList<QGraphicsItem *> itemsInScene = captureScene->items();
    int width = static_cast<GraphicsImageItem *>(itemsInScene.at(0))->getWidth();
    int viewWidth = captureView->width();
    int itemsInRow = viewWidth / (width * scale) + 1;
    for(int i=0;i<itemsInScene.count();i++)
    {
        GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(i));
        int xpos = i%itemsInRow;
        int ypos = i/itemsInRow;
        gii->setPos(xpos * gii->getWidth(), ypos * gii->getHeight());
    }
    captureView->setMatrix(matrix);
}

void CaptureFileViewer::resetFrameSlider(PFCMU::timestamp_t minValue, PFCMU::timestamp_t maxValue)
{
    sliderFrames->setMinimum(0);
    sliderFrames->setMaximum((maxValue-minValue)/TIMESTAMPINC);
    sliderFrames->setValue(sliderFrames->minimum());
    labelMinTimeStamp->setText(tr("%1").arg(minValue));
    labelMaxTimeStamp->setText(tr("%1").arg(maxValue));
//    labelCurrentTimeStamp->setText(tr("%1").arg(minValue));
    txtCurrentFrame->setText(tr("%1").arg(minValue));
}

void CaptureFileViewer::onFrameChanged(int value)
{
//    labelCurrentTimeStamp->setText(tr("%1").arg(m_MinFileGroupTimeStamp+value*TIMESTAMPINC));
    txtCurrentFrame->setText(tr("%1").arg(m_MinFileGroupTimeStamp+value*TIMESTAMPINC));
    emit timeStampChanged(m_MinFileGroupTimeStamp+value*TIMESTAMPINC);
}

void CaptureFileViewer::onCamsChanged(int value)
{
    labelCurrentCam->setText(tr("%1").arg(sliderCams->value()));
    emit camChanged(sliderCams->value());
}

void CaptureFileViewer::onSwitchToSingle(QString *file)
{
    QString fileStr(*file);
    qDebug(fileStr.toAscii());
    buttonViewAll->setChecked(false);
    buttonViewAll->setEnabled(true);
    buttonPlay->setEnabled(true);
    buttonPause->setEnabled(false);

    PFCMU::timestamp_t minTimeStamp;
    PFCMU::timestamp_t maxTimeStamp;
    QFileInfo fi(fileStr);
    if(fi.exists())
    {
        captureScene->clear();
        int width = 640;
        if(TIMESTAMPINC==4)
        {
            width = 640;
        }
        else
        {
            width = 320;
        }
        GraphicsImageItem *gii = new GraphicsImageItem(&fileStr,width);
        minTimeStamp = gii->getMinTimeStamp();
        maxTimeStamp = gii->getMaxTimeStamp();
        this->resetFrameSlider(minTimeStamp,maxTimeStamp);
        connect(this, SIGNAL(initTimeStamp(PFCMU::timestamp_t)),
                gii, SLOT(onInitTimeStamp(PFCMU::timestamp_t)));
        connect(this, SIGNAL(timeStampChanged(PFCMU::timestamp_t)),
                gii, SLOT(onTimeStampUpdated(PFCMU::timestamp_t)));
        connect(this, SIGNAL(camChanged(int)),
                gii, SLOT(onCamUpdated(int)));
        captureScene->addItem(gii);
        labelSingleView->setText(gii->getName());
    }
}

void CaptureFileViewer::onSwitchToAll()
{
    buttonPlay->setEnabled(false);
    buttonPause->setEnabled(false);
    labelSingleView->setText(tr("Not Set"));
    buttonViewAll->setEnabled(false);
    this->onRefreshView();
}

void CaptureFileViewer::onPlay()
{
    QList<QGraphicsItem *> itemsInScene = captureScene->items();
    GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(0));
    disconnect(gii, SLOT(onTimeStampUpdated(PFCMU::timestamp_t)));
    //connect(this, SIGNAL(timeStampChanged(PFCMU::timestamp_t)), gii, SLOT(onPlayTimeStampUpdated(PFCMU::timestamp_t)));
    connect(gii, SIGNAL(oneFrameFinished()), SLOT(onOneFrameFinished()));
    sliderFrames->setValue(sliderFrames->value()+1);
    gii->onPlayTimeStampUpdated(m_MinFileGroupTimeStamp+sliderFrames->value()*TIMESTAMPINC);
}
bool playok = true;
void CaptureFileViewer::onOneFrameFinished()
{
    QList<QGraphicsItem *> itemsInScene = captureScene->items();
    GraphicsImageItem *gii = static_cast<GraphicsImageItem *>(itemsInScene.at(0));
    if(sliderFrames->value()<sliderFrames->maximum())
    {
        sliderFrames->setValue(sliderFrames->value()+1);
        if(playok)
        {
            playok=false;
            gii->onPlayTimeStampUpdated(m_MinFileGroupTimeStamp+sliderFrames->value()*TIMESTAMPINC);

        }

    }
}

void CaptureFileViewer::setTimeStampInc()
{
    if(rdo100Fps->isChecked())
        TIMESTAMPINC = 1;
    else
        TIMESTAMPINC = 4;
}
